package com.github.shuaidd.rest;

import com.github.shuaidd.model.dto.BpmnXmlDTO;
import com.github.shuaidd.model.response.ResultObject;
import com.github.shuaidd.model.vo.ProcessModelVO;
import com.github.shuaidd.service.transfer.TransferService;
import com.github.shuaidd.service.util.XMLUtil;
import org.activiti.engine.ProcessEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileNotFoundException;
import java.util.List;

/**
 * 描述
 *
 * @author ddshuai
 * @date 2020-07-12 10:09
 **/
@RestController
@RequestMapping("/lwf/process")
public class ProcessRestController {
    private final ProcessEngine processEngine;
    private final TransferService transferService;

    @Autowired
    public ProcessRestController(ProcessEngine processEngine, TransferService transferService) {
        this.processEngine = processEngine;
        this.transferService = transferService;
    }

    @GetMapping("transfer/{code}")
    public ResultObject<String> transfer(@PathVariable String code) throws FileNotFoundException {
        BpmnXmlDTO xml = transferService.transfer(code);
        return ResultObject.ok(XMLUtil.convertToXml(xml));
    }

    @GetMapping("list")
    public ResultObject<List<ProcessModelVO>> processModels() throws FileNotFoundException {
        return ResultObject.ok(transferService.list());
    }
}
